const express = require('express');
const router = express.Router();
const markPaperController = require('../controllers/markPaper.controller');
const { verifyToken, isSubjectGroupLeader, isTeacher } = require('../middlewares/auth.middleware');

// 自定义中间件：检查用户是否为学科组长或教师
const isSubjectGroupLeaderOrTeacher = (req, res, next) => {
  // 如果roleId为2(学科组长)或3(教师)，则允许访问
  if (req.roleId === 2 || req.roleId === 3) {
    next();
  } else {
    return res.status(403).json({ 
      code: 403,
      message: '需要学科组长或教师权限',
      success: false
    });
  }
};

// 获取整张试卷批阅数据
router.post('/wholePaperBatchReview', verifyToken, isSubjectGroupLeaderOrTeacher, markPaperController.wholePaperBatchReview);

// 获取单道大题批阅数据
router.post('/singleQuestionReview', verifyToken, isSubjectGroupLeaderOrTeacher, markPaperController.singleQuestionReview);

// 保存当前批阅
router.post('/saveCurrentCheck', verifyToken, isSubjectGroupLeaderOrTeacher, markPaperController.saveCurrentCheck);

module.exports = router;
